package com.huangyi.ack.listener;

import com.huangyi.ack.constants.Constants;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
@Component
public class ManualListener {
    @RabbitListener(queues = Constants.AKC_QUEUE_MANUAL)
    public void listen(Message message, Channel channel) throws Exception {
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        try{
            System.out.println("接收到消息: "+ new String(message.getBody(),"UTF-8")+
                    "deliveryTag: " + message.getMessageProperties().getDeliveryTag() );
            System.out.println("auto 业务逻辑处理完毕");
            channel.basicAck(deliveryTag,false);
        }catch(Exception e){
            // tag 是否批量 是否确认
            channel.basicNack(deliveryTag,false,true);

        }
    }
}
